package com.example.lockandqueue;

import java.util.concurrent.locks.ReentrantLock;

public class ReentrantLockMain {

    static ReentrantLock lock = new ReentrantLock();

    public void test(){
        lock.lock();
        try {
            System.out.println(Thread.currentThread().getName()+"lock start");
            lock.lock();
            System.out.println("1111");
            Thread.sleep(5000);
            System.out.println(Thread.currentThread().getName()+"lock end");
        } catch (Exception e){
            e.printStackTrace();
        }finally {
            lock.unlock();
        }
    }

    public static void main(String[] args) {
        ReentrantLockMain reentrantLockMain = new ReentrantLockMain();
        new Thread(()->{
            reentrantLockMain.test();
        }).start();
//        ReentrantLockMain reentrantLockMain1 = new ReentrantLockMain();
//        new Thread(()->{
//            reentrantLockMain1.test();
//        }).start();
    }

}
